home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume16 / ecu3 / part06 < prev    next >
Encoding:
Internet Message Format  |  1991-01-06  |  42.9 KB

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i030:  ECU async comm package rev 3.0, Part06/35
  4. Message-ID: <1991Jan6.051854.27514@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:18:54 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: b868e209 094d563a 31fb9e38 5eff60a1
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 30
  11. Archive-name: ecu3/part06
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 06 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= ecuphrase.c ==============
  21. echo 'x - extracting ecuphrase.c (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'ecuphrase.c' &&
  23. X/*+-----------------------------------------------------------------
  24. X    ecuphrases.c - %# phrase management
  25. X    wht@n4hgf.Mt-Park.GA.US
  26. X
  27. X  Defined functions:
  28. X    phrase_help()
  29. X    phrases(nargc,nargv)
  30. X    read_phrases()
  31. X
  32. X------------------------------------------------------------------------*/
  33. X/*+:EDITS:*/
  34. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  35. X
  36. X#include "ecu.h"
  37. X
  38. X#define P_N_QUAN    23
  39. Xchar *phrases_string[P_N_QUAN];
  40. Xchar *phrases_label[P_N_QUAN];
  41. Xint phrases_count = 0;
  42. Xint phrases_resident = 0;
  43. X
  44. X/*+-----------------------------------------------------------------------
  45. X    read_phrases()
  46. X------------------------------------------------------------------------*/
  47. Xvoid
  48. Xread_phrases()
  49. X{
  50. Xregister char *phrases_str;
  51. Xchar phrases_buf[256];
  52. Xchar phrases_buf_copy[256];
  53. Xchar *phrases_lbl;
  54. XFILE *fd_phrase;
  55. X
  56. X    if(phrases_resident)
  57. X    {
  58. X        while(phrases_count)
  59. X            free(phrases_string[--phrases_count]);
  60. X        phrases_resident = 0;
  61. X    }
  62. X
  63. X    get_home_dir(phrases_buf);
  64. X    strcat(phrases_buf,"/.ecu/phrases");
  65. X
  66. X    if( (fd_phrase = fopen(phrases_buf,"r")) == NULL)
  67. X    {
  68. X        ff(se,"\r\n");
  69. X        perror(phrases_buf);
  70. X        ff(se,"\r\n");
  71. X        ff(se,"... no phrases resident\r\n");
  72. X        return;
  73. X    }
  74. X
  75. X/* we have an open .ecu/phrase file */
  76. X    phrases_count = 0;
  77. X    while(fgets(phrases_buf,sizeof(phrases_buf),fd_phrase) != NULL)
  78. X    {
  79. X        phrases_buf[strlen(phrases_buf) - 1] = 0;
  80. X        if(strlen(phrases_buf) == 0)
  81. X            continue;
  82. X
  83. X        if(phrases_count == P_N_QUAN)
  84. X        {
  85. X            ff(se,"\r\nMaximum number of phrases %d exceeded\r\n",P_N_QUAN);
  86. X            ff(se,"rest of file ignored, starting with the following:\r\n");
  87. X            ff(se,"--> %s\r\n\r\n",phrases_buf);
  88. X            phrases_resident = 1;
  89. X            fclose(fd_phrase);
  90. X            return;
  91. X        }
  92. X        strcpy(phrases_buf_copy,phrases_buf);
  93. X        phrases_lbl = phrases_buf_copy;
  94. X        for(phrases_str = phrases_buf_copy; *phrases_str; phrases_str++)
  95. X        {
  96. X            if(*phrases_str == ':')
  97. X            {
  98. X                *phrases_str++ = 0;
  99. X                break;
  100. X            }
  101. X            if(*phrases_str == 0)
  102. X            {
  103. X                ff(se,"invalid entry `%s'\n",phrases_buf);
  104. X                continue;
  105. X            }
  106. X        }
  107. X
  108. X        if(!(phrases_string[phrases_count] = malloc(strlen(phrases_str)+2)) ||
  109. X           !(phrases_label[phrases_count] = malloc(strlen(phrases_lbl)+2)))
  110. X        {
  111. X            ff(se,"\r\nNo more memory for phrases\r\n");
  112. X            ff(se,"rest of file ignored, starting with the following:\r\n");
  113. X            ff(se,"--> %s\r\n\r\n",phrases_buf);
  114. X            phrases_resident = 1;
  115. X            fclose(fd_phrase);
  116. X            if(phrases_string[phrases_count])
  117. X                free(phrases_string[phrases_count]);
  118. X            return;
  119. X        }
  120. X        strcpy(phrases_string[phrases_count],phrases_str);
  121. X        strcpy(phrases_label[phrases_count],phrases_lbl);
  122. X        phrases_count++;
  123. X    }            /* while records left to read */
  124. X
  125. X    fclose(fd_phrase);
  126. X    phrases_resident = 1;
  127. X}    /* end of read_phrases */
  128. X
  129. X/*+-------------------------------------------------------------------------
  130. X    phrases(nargc,nargv)
  131. X--------------------------------------------------------------------------*/
  132. Xphrases(nargc,nargv)
  133. Xint nargc;
  134. Xchar **nargv;
  135. X{
  136. Xregister itmp;
  137. Xregister ichar;
  138. Xregister char *cptr;
  139. Xint old_ttymode = get_ttymode();
  140. Xextern char *phrases_string[]; 
  141. Xextern int phrases_count;
  142. Xextern int phrases_resident;
  143. Xextern int interrupt;
  144. Xextern int icmd_prompt_len;
  145. X
  146. X    for(itmp = icmd_prompt_len + strlen(nargv[0]); itmp; itmp--)
  147. X        fputs("\b \b",se);
  148. X
  149. X    itmp = atoi(nargv[0]);
  150. X
  151. X    if(itmp == 0)
  152. X    {
  153. X        ff(se,"\r\n");
  154. X        read_phrases();
  155. X        if(!phrases_count)
  156. X            return(0);
  157. X        tcap_stand_out();
  158. X        ff(se,
  159. X" # |  mnemonic    |     phrase                                              ");
  160. X        tcap_stand_end();
  161. X        ff(se,"\r\n");
  162. X        for(itmp = 0; itmp < phrases_count; itmp++)
  163. X            ff(se,"%2d | %12s |  %s\r\n",itmp + 1,phrases_label[itmp],
  164. X                        phrases_string[itmp]);
  165. X        return(0);
  166. X    }
  167. X    else
  168. X        if(phrases_resident == 0)
  169. X            read_phrases();
  170. X
  171. X    if(itmp > phrases_count)
  172. X    {
  173. X        ff(se,"  unknown: %d\r\n",itmp);
  174. X        return(-1);
  175. X    }
  176. X    else
  177. X    {
  178. X        cptr = phrases_string[itmp - 1];
  179. X        ttymode(2);
  180. X        while(*cptr)
  181. X        {
  182. X            if(interrupt)
  183. X                break;
  184. X
  185. X            switch(ichar = *cptr++)
  186. X            {
  187. X                case '^':
  188. X                    ichar = *cptr++;
  189. X                    if((ichar >= '@') && (ichar <= '_'))
  190. X                        lputc_paced(0,ichar & 0x1F);
  191. X                    else if(ichar == '?')
  192. X                        lputc_paced(0,0x7F);
  193. X                    else
  194. X                    {
  195. X                        switch(ichar)
  196. X                        {
  197. X                            case 0:
  198. X                                goto NULL_FOUND;
  199. X                            case 'r':
  200. X                                lputc_paced(0,'\r');
  201. X                                break;
  202. X                            case 'n':
  203. X                                lputc_paced(0,'\n');
  204. X                                break;
  205. X                            case 't':
  206. X                                lputc_paced(0,'\t');
  207. X                                break;
  208. X                            case '^':
  209. X                                lputc_paced(0,'^'); 
  210. X                                break;
  211. X                            case 'p': 
  212. X                                itmp = atoi(cptr);
  213. X                                while((*cptr >= '0') && (*cptr <= '9'))
  214. X                                    cptr++;
  215. X                                if(*cptr == '.')
  216. X                                    cptr++;
  217. X                                if(!itmp)
  218. X                                    itmp = 1;
  219. X                                nap((long)itmp * 100L);
  220. X                                break;
  221. X                            case 'a':
  222. X                                itmp = atoi(cptr);
  223. X                                while((*cptr >= '0') && (*cptr <= '9'))
  224. X                                    cptr++;
  225. X                                if(*cptr == '.')
  226. X                                    cptr++;
  227. X                                if(itmp < nargc)
  228. X                                {
  229. X                                    lputs_paced(0,nargv[itmp]);
  230. X                                    itmp = strlen(nargv[itmp]);
  231. X                                }
  232. X                                break;
  233. X                        }
  234. X                    }
  235. X                    break;
  236. X                default:
  237. X                    lputc_paced(0,ichar);
  238. X            }
  239. X        }
  240. X
  241. XNULL_FOUND:
  242. X        if(interrupt)
  243. X        {
  244. X            interrupt = 0;
  245. X            ff(se,"\r\n--> interrupted\r\n");
  246. X        }
  247. X
  248. X    }
  249. X
  250. X    ttymode(old_ttymode);
  251. X    return(0);
  252. X
  253. X}    /* end of phrases */
  254. X
  255. X
  256. X/*+-------------------------------------------------------------------------
  257. X    phrase_help()
  258. X--------------------------------------------------------------------------*/
  259. Xvoid
  260. Xphrase_help()
  261. X{
  262. X    ff(se,"^r == \\r    ^n == \\n   ^t == \\t  ^^ == '^'\r\n");
  263. X    ff(se,"^p#.  pause # secs\r\n");
  264. X    ff(se,"^a#.  arg number # of %%# invocation\r\n");
  265. X}    /* end of phrase_help */
  266. X/* vi: set tabstop=4 shiftwidth=4: */
  267. SHAR_EOF
  268. $TOUCH -am 1224223290 'ecuphrase.c' &&
  269. chmod 0644 ecuphrase.c ||
  270. echo 'restore of ecuphrase.c failed'
  271. Wc_c="`wc -c < 'ecuphrase.c'`"
  272. test 5521 -eq "$Wc_c" ||
  273.     echo 'ecuphrase.c: original size 5521, current size' "$Wc_c"
  274. # ============= ecurcvr.c ==============
  275. echo 'x - extracting ecurcvr.c (Text)'
  276. sed 's/^X//' << 'SHAR_EOF' > 'ecurcvr.c' &&
  277. X#define DEFENSIVE        /* lots of changes this rev: defining this
  278. X                         * will make for screwed up screen image
  279. X                         * but no core dump if nassssty bugs show up
  280. X                         */
  281. X/* #define ANSI_DEBUG */        /* debug ansi */
  282. X/* #define ANSI_DEBUG_2 */        /* debug ansi intensive output */
  283. X/* #define ANSI_DEBUG_3 */        /* debug ansi selected output */
  284. X/* #define ANSI_DEBUG_NOBUF */    /* unbufferred logging */
  285. X/* #define ANSI_DEBUG_LOGFILE    "/dev/tty2h" */
  286. X/* #define DEBUG_CURSOR */
  287. X#ifdef TEMP_HACK
  288. X#define ANSI_DEBUG
  289. X#define ANSI_DEBUG_2
  290. X#define ANSI_DEBUG_3
  291. X#define ANSI_DEBUG_LOGFILE    "/t/ansi.log"
  292. X#endif
  293. X
  294. X/*+-------------------------------------------------------------------------
  295. X    ecurcvr.c - rcvr process + ANSI filter + non-ANSI<->ANSI hoop jumping
  296. X    wht@n4hgf.Mt-Park.GA.US
  297. X
  298. X  Defined functions:
  299. X    accumulate_ansi_sequence(rchar)
  300. X    ansi_CNL()
  301. X    ansi_CPL()
  302. X    ansi_CUB()
  303. X    ansi_CUD()
  304. X    ansi_CUF()
  305. X    ansi_CUP()
  306. X    ansi_CUU()
  307. X    ansi_DCH()
  308. X    ansi_DL()
  309. X    ansi_DSR()
  310. X    ansi_ECH()
  311. X    ansi_ED()
  312. X    ansi_EL()
  313. X    ansi_HPA()
  314. X    ansi_ICH()
  315. X    ansi_IL()
  316. X    ansi_SD()
  317. X    ansi_SGR()
  318. X    ansi_SU()
  319. X    ansi_VPA()
  320. X    is_ansi_terminator(rchar)
  321. X    lgetc_rcvr()
  322. X    process_ansi_sequence()
  323. X    process_rcvd_char(rchar)
  324. X    rcvd_ESC()
  325. X    rcvr()
  326. X    rcvr_log_open()
  327. X    redisplay_rcvr_screen()
  328. X    saved_cursor_restore_cursor()
  329. X    saved_cursor_save_cursor()
  330. X    spaces(buf,buflen)
  331. X    spaces_trap(code,buf,buflen)
  332. X
  333. X--------------------------------------------------------------------------*/
  334. X/*+:EDITS:*/
  335. X/*:12-21-1990-21:06-wht@n4hgf-CUF and CUB set non-ansi cursor incorrectly */
  336. X/*:12-20-1990-16:27-wht@n4hgf-had SU and SD swapped */
  337. X/*:11-30-1990-18:39-wht@n4hgf-non-ansi console rcvr appears to be working */
  338. X/*:11-28-1990-14:13-wht@n4hgf-start non-ansi console support */
  339. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  340. X
  341. X#include "ecu.h"
  342. X#include "ecukey.h"
  343. X
  344. Xextern int errno;
  345. Xextern char rcvr_log_file[];    /* if rcvr_log!= 0,log filename */
  346. Xextern int rcvr_log;            /* rcvr log active if != 0 */
  347. Xextern FILE *rcvr_log_fp;        /* rcvr log file */
  348. Xextern int rcvr_log_raw;        /* if true, log all, else filter ctl chrs */
  349. Xextern int rcvr_log_append;        /* if true, append, else scratch */
  350. Xextern int rcvr_log_flusheach;    /* if true, flush log on each char */
  351. Xextern int rcvr_log_gen_title;
  352. X
  353. Xextern int want_bell_notify;
  354. Xextern uint tcap_LINES;    /* terminal line quantity - see ecutcap.c */
  355. Xextern uint tcap_COLS;    /* terminal column quantity - see ecutcap.c */
  356. Xextern uint LINESxCOLS;
  357. Xextern int tty_is_ansi;        /* true if TERM contains "ansi" */
  358. X
  359. Xstatic char esc = ESC;
  360. X#define MAX_ANSI_LEN    30    /* generous */
  361. Xchar ansibuf[MAX_ANSI_LEN];
  362. Xchar *ansi;
  363. Xint ansilen = 0;
  364. Xint in_ansi_accumulation = 0;
  365. X
  366. Xint saved_cursor_y;
  367. Xint saved_cursor_x;
  368. X
  369. X#define RCVR_RDQUAN        250
  370. Xchar lgetc_buf[RCVR_RDQUAN];
  371. Xchar *lgetc_ptr;
  372. Xint lgetc_count = 0;
  373. Xint vmin;                /* quick copy of current vmin value */
  374. X
  375. X#ifdef ANSI_DEBUG
  376. XFILE *wfp = (FILE *)0;
  377. X#endif
  378. X
  379. X/*+-------------------------------------------------------------------------
  380. X    redisplay_rcvr_screen() - redisplay logical receiver screen
  381. XAs of writing, this function is called only by the XMTR process
  382. X--------------------------------------------------------------------------*/
  383. Xvoid
  384. Xredisplay_rcvr_screen()
  385. X{
  386. Xregister uint y;
  387. X
  388. X    setcolor(colors_current);
  389. X    tcap_stand_end();
  390. X    for(y = 0; y < tcap_LINES; y++)
  391. X    {
  392. X        tcap_cursor(y,0);
  393. X        fwrite(&shm->screen[y][0],
  394. X            ((y != tcap_LINES - 1) ? tcap_COLS : tcap_COLS - 1),
  395. X            1,se);
  396. X    }
  397. X    tcap_eeol();
  398. X    tcap_cursor(shm->cursor_y,shm->cursor_x);
  399. X
  400. X}    /* end of redisplay_rcvr_screen */
  401. X
  402. X#ifdef DEBUG_CURSOR
  403. Xvoid
  404. Xspaces_trap(code,buf,buflen)
  405. Xint code;
  406. Xregister uchar *buf;
  407. Xregister uint buflen;
  408. X{
  409. Xchar *xyz = (char *)0x90000000;
  410. X    ff(se,"rcvr 'spaces trap' code %d: cursor x,y=%d,%d\r\n",
  411. X        code,
  412. X        shm->cursor_y,shm->cursor_x);
  413. X    ff(se,"buf=%08lx len=%08lx offs=%08lx\r\n",buf,buflen,
  414. X        (ulong)buf - (ulong)shm->screen);
  415. X    *xyz = 0;
  416. X    abort();
  417. X}
  418. X#endif
  419. X
  420. X/*+-------------------------------------------------------------------------
  421. X    spaces(buf,buflen) - fill with spaces
  422. X--------------------------------------------------------------------------*/
  423. Xvoid
  424. Xspaces(buf,buflen)
  425. Xregister uchar *buf;
  426. Xregister uint buflen;
  427. X{
  428. X#ifdef DEBUG_CURSOR
  429. X    if((ulong)buf > (((ulong)shm->screen) + LINESxCOLS))
  430. X        spaces_trap(1,buf,buflen);
  431. X    if((ulong)buf < (ulong)shm->screen)
  432. X        spaces_trap(2,buf,buflen);
  433. X    if((ulong)(buf + buflen) > (((ulong)shm->screen) + LINESxCOLS))
  434. X        spaces_trap(3,buf,buflen);
  435. X    if((ulong)(buf + buflen) < (ulong)shm->screen)
  436. X        spaces_trap(4,buf,buflen);
  437. X#endif
  438. X
  439. X    if(!buflen)
  440. X        return;
  441. X
  442. X#ifdef DEFENSIVE
  443. X    if((ulong)buf < (ulong)shm->screen)
  444. X        return;
  445. X    if((ulong)(buf + buflen) > (((ulong)shm->screen) + LINESxCOLS))
  446. X        return;
  447. X#endif
  448. X
  449. X    while(buflen--)
  450. X        *buf++ = ' ';
  451. X}    /* end of spaces */
  452. X
  453. X/*+-------------------------------------------------------------------------
  454. X    lgetc_rcvr() - rcvr version of get char from line
  455. X--------------------------------------------------------------------------*/
  456. Xint
  457. Xlgetc_rcvr()
  458. X{
  459. Xextern int errno;
  460. Xchar char_rtnd;
  461. X
  462. X    if(!lgetc_count)
  463. X    {
  464. X        if(vmin == 1)
  465. X        {
  466. X            char_rtnd = lgetc_xmtr();
  467. X            return(char_rtnd);
  468. X        }
  469. X        lgetc_ptr = lgetc_buf;
  470. XREAD_AGAIN:
  471. X        errno = 0;
  472. X        if((lgetc_count =
  473. X            read(shm->Liofd,lgetc_buf,RCVR_RDQUAN)) < 0)
  474. X        {
  475. X            if(errno == EINTR)            /* if signal interrupted, ... */
  476. X                goto READ_AGAIN;
  477. X            hangup(HANGUP_LINE_READ_ERROR);
  478. X        }
  479. X        shm->rcvd_chars += lgetc_count;
  480. X        shm->rcvd_chars_this_connect += lgetc_count;
  481. X
  482. X    }
  483. X    if(!lgetc_count)
  484. X        goto READ_AGAIN;
  485. X
  486. X    lgetc_count--;
  487. X    return(*lgetc_ptr++);
  488. X}    /* end of lgetc_rcvr */
  489. X
  490. X/*+-------------------------------------------------------------------------
  491. X    ansi_SGR() - Set Graphics Rendition
  492. X
  493. XThe DOS ANSI world expects to be able to be able to chain 0,1 and
  494. X3x,4x params together with semicolons.
  495. X
  496. X  Supported modifiers for non-ansi terminals
  497. X  0       normal
  498. X  1       bold
  499. X  4       underscore
  500. X  5       blink
  501. X  7       reverse video
  502. X--------------------------------------------------------------------------*/
  503. Xvoid
  504. Xansi_SGR()
  505. X{
  506. Xregister itmp;
  507. Xregister char *cptr;
  508. Xchar SGRstr[MAX_ANSI_LEN];
  509. Xchar *token;
  510. Xchar *str_token();
  511. X
  512. X    if(!tty_is_ansi)
  513. X    {
  514. X        cptr = ansibuf;
  515. X        while(token = str_token(cptr,";"))
  516. X        {
  517. X            cptr = (char *)0;    /* further calls to str_token need NULL */
  518. X            switch(atoi(token))
  519. X            {
  520. X                case 0:        /* normal */
  521. X                    tcap_stand_end();
  522. X                    tcap_blink_off();
  523. X                    tcap_underscore_off();
  524. X                    tcap_bold_off();
  525. X                    break;
  526. X                case 1:        /* bold */
  527. X                    tcap_bold_on();
  528. X                    break;
  529. X                case 4:        /* underscore */
  530. X                    tcap_underscore_on();
  531. X                    break;
  532. X                case 5:        /* blink */
  533. X                    tcap_blink_on();
  534. X                    break;
  535. X                case 7:        /* reverse video */
  536. X                    tcap_stand_out();
  537. X                    break;
  538. X                default:
  539. X                    break;
  540. X            }
  541. X        }
  542. X        return;
  543. X    }
  544. X
  545. X    if(ansilen <= 3)    /* 'ESC[<0-9>m' and 'ESC[m' - quickly handled */
  546. X    {
  547. X        write(TTYERR,&esc,1);
  548. X        write(TTYERR,ansibuf,ansilen);
  549. X        return;
  550. X    }
  551. X
  552. X/* check XENIX 'ESC[<2,3,7>m' extensions */
  553. X    switch(itmp = atoi(ansibuf + 1))
  554. X    {
  555. X        case 7: /* XENIX 'ESC[7;<0-15>;<0-15>m' set fore/background color */
  556. X            itmp = atoi(ansibuf + 3);    /* second parameter */
  557. X            if(itmp > 15)                /* not XENIX extension */
  558. X                break;
  559. X            /* fall through */
  560. X        case 2:    /* XENIX 'ESC[2;<0-15>;<0-15>m' set fore/background color */
  561. X        case 3:    /* XENIX 'ESC[3;<0-1>m' color only set/clear blink */
  562. X            write(TTYERR,&esc,1);
  563. X            write(TTYERR,ansibuf,ansilen);
  564. X            return;
  565. X        default:
  566. X            break;
  567. X    }
  568. X
  569. X/* not XENIX extension */
  570. X    ansibuf[ansilen - 1] = 0;    /* get rid of 'm' */
  571. X    cptr = ansibuf + 1;            /* get rid of '[' */
  572. X
  573. X    while(token = str_token(cptr,";"))
  574. X    {
  575. X        cptr = (char *)0;    /* further calls to str_token need NULL */
  576. X        sprintf(SGRstr,"\033[%sm",token);
  577. X        write(TTYERR,SGRstr,strlen(SGRstr));
  578. X    }
  579. X
  580. X}    /* end of ansi_SGR */
  581. X
  582. X/*+-------------------------------------------------------------------------
  583. X    ansi_CUP() - cursor position (also HVP horiz/vertical position)
  584. X--------------------------------------------------------------------------*/
  585. Xvoid
  586. Xansi_CUP()
  587. X{
  588. Xregister uint param_count = 0;
  589. Xchar ansicopy[MAX_ANSI_LEN];
  590. Xregister char *cptr = ansicopy;
  591. Xregister char *token;
  592. Xchar *str_token();
  593. X
  594. X    strcpy(cptr,ansibuf + 1);
  595. X    *(cptr + ansilen - 2) = 0;
  596. X
  597. X    while(token = str_token(cptr,";"))
  598. X    {
  599. X        cptr = (char *)0;    /* further calls to str_token need NULL */
  600. X        switch(++param_count)
  601. X        {
  602. X            case 1:    shm->cursor_y = atoi(token) - 1; break;
  603. X            case 2:    shm->cursor_x = atoi(token) - 1; break;
  604. X        }
  605. X    }
  606. X    switch(param_count)
  607. X    {
  608. X        case 0:
  609. X            shm->cursor_y = 0;
  610. X        case 1:
  611. X            shm->cursor_x = 0;
  612. X    }
  613. X    if(shm->cursor_x > (tcap_COLS - 1))
  614. X        shm->cursor_x = 0;
  615. X    if(shm->cursor_y > (tcap_LINES - 1))
  616. X        shm->cursor_y = 0;
  617. X
  618. X    if(!tty_is_ansi)
  619. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  620. X
  621. X}    /* end of ansi_CUP */
  622. X
  623. X/*+-------------------------------------------------------------------------
  624. X    ansi_CUU() - cursor up
  625. X--------------------------------------------------------------------------*/
  626. Xvoid
  627. Xansi_CUU()
  628. X{
  629. Xregister uint count;
  630. Xregister uint y;
  631. X
  632. X    if(ansilen == 2)        /* no param */
  633. X        count = 1;
  634. X    else
  635. X        count = atoi(ansibuf + 1);
  636. X
  637. X    y = shm->cursor_y - count;
  638. X    if(y > (tcap_LINES - 1))    /* unsigned comparison */
  639. X        y = 0;
  640. X
  641. X    if(y != shm->cursor_y)
  642. X    {
  643. X        shm->cursor_y = y;
  644. X        if(!tty_is_ansi)
  645. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  646. X    }
  647. X
  648. X}    /* end of ansi_CUU */
  649. X
  650. X/*+-------------------------------------------------------------------------
  651. X    ansi_CUD() - cursor down (also VPR vertical position relative)
  652. X--------------------------------------------------------------------------*/
  653. Xvoid
  654. Xansi_CUD()
  655. X{
  656. Xregister uint count;
  657. Xregister uint y;
  658. X
  659. X    if(ansilen == 2)        /* no param */
  660. X        count = 1;
  661. X    else
  662. X        count = atoi(ansibuf + 1);
  663. X
  664. X    y = shm->cursor_y + count;
  665. X    if(y > (tcap_LINES - 1))
  666. X        y = tcap_LINES - 1;
  667. X
  668. X    if(y != shm->cursor_y)
  669. X    {
  670. X        shm->cursor_y = y;
  671. X        if(!tty_is_ansi)
  672. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  673. X    }
  674. X
  675. X}    /* end of ansi_CUD */
  676. X
  677. X/*+-------------------------------------------------------------------------
  678. X    ansi_CUF() - cursor forward (also HPR horizontal position relative)
  679. X--------------------------------------------------------------------------*/
  680. Xvoid
  681. Xansi_CUF()
  682. X{
  683. Xregister uint count;
  684. Xregister uint x;
  685. X
  686. X    if(ansilen == 2)        /* no param */
  687. X        count = 1;
  688. X    else
  689. X        count = atoi(ansibuf + 1);
  690. X
  691. X    x = shm->cursor_x + count;
  692. X    if(x > tcap_COLS - 1)
  693. X        x = tcap_COLS - 1;
  694. X
  695. X    if(x != shm->cursor_x)
  696. X    {
  697. X        shm->cursor_x = x;
  698. X        if(!tty_is_ansi)
  699. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  700. X    }
  701. X
  702. X}    /* end of ansi_CUF */
  703. X
  704. X/*+-------------------------------------------------------------------------
  705. X    ansi_CUB() - cursor forward
  706. X--------------------------------------------------------------------------*/
  707. Xvoid
  708. Xansi_CUB()
  709. X{
  710. Xregister uint count;
  711. Xregister uint x;
  712. X
  713. X    if(ansilen == 2)        /* no param */
  714. X        count = 1;
  715. X    else
  716. X        count = atoi(ansibuf + 1);
  717. X
  718. X    x = shm->cursor_x - count;
  719. X    if(x > (tcap_COLS - 1))    /* unsigned comparison */
  720. X        x = 0;
  721. X
  722. X    if(x != shm->cursor_x)
  723. X    {
  724. X        shm->cursor_x = x;
  725. X        if(!tty_is_ansi)
  726. X            tcap_cursor(shm->cursor_y,shm->cursor_x);
  727. X    }
  728. X
  729. X}    /* end of ansi_CUB */
  730. X
  731. X/*+-------------------------------------------------------------------------
  732. X    ansi_DSR() - device status report
  733. X--------------------------------------------------------------------------*/
  734. Xvoid
  735. Xansi_DSR()
  736. X{
  737. Xchar response[MAX_ANSI_LEN];
  738. X
  739. X    sprintf(response,"\033[%d;%dR",shm->cursor_y + 1,shm->cursor_x + 1);
  740. X    write(shm->Liofd,response,strlen(response));
  741. X
  742. X}    /* end of ansi_DSR */
  743. X
  744. X/*+-------------------------------------------------------------------------
  745. X    ansi_ED() - erase in display
  746. X--------------------------------------------------------------------------*/
  747. Xvoid
  748. Xansi_ED()
  749. X{
  750. Xregister uint param;
  751. Xint y;
  752. X
  753. X    if(ansilen == 2)        /* no param */
  754. X        param = 0;
  755. X    else
  756. X        param = atoi(ansibuf + 1);
  757. X
  758. X    switch(param)
  759. X    {
  760. X        case 0:    /* erase to end of display */
  761. X            spaces(&shm->screen[shm->cursor_y][shm->cursor_x],
  762. X                LINESxCOLS - ((shm->cursor_y * tcap_COLS) + shm->cursor_x));
  763. X            if(!tty_is_ansi)
  764. X                tcap_eeod();
  765. X            break;
  766. X        case 1:    /* erase from beginning of display */
  767. X            spaces((char *)shm->screen,(shm->cursor_y * tcap_COLS) +
  768. X                shm->cursor_x);
  769. X            if(!tty_is_ansi)
  770. X            {
  771. X                for(y = 0; y < shm->cursor_y - 1; y++)
  772. X                {
  773. X                    tcap_cursor(y,0);
  774. X                    tcap_eeol();
  775. X                }
  776. X                if(shm->cursor_x)
  777. X                {
  778. X                    tcap_cursor(shm->cursor_y,0);
  779. X                    tcap_clear_area_char(shm->cursor_x,' ');
  780. X                }
  781. X                else
  782. X                    tcap_cursor(shm->cursor_y,shm->cursor_x);
  783. X            }
  784. X            break;
  785. X        case 2:    /* clear display */
  786. X            shm->cursor_y = 0;
  787. X            shm->cursor_x = 0;
  788. X            spaces((char *)shm->screen,LINESxCOLS);
  789. X            if(!tty_is_ansi)
  790. X            {
  791. X                tcap_clear_screen();
  792. X                tcap_cursor(shm->cursor_y,shm->cursor_x);
  793. X            }
  794. X            break;
  795. X    }
  796. X
  797. X}    /* end of ansi_ED */
  798. X
  799. X/*+-------------------------------------------------------------------------
  800. X    ansi_EL() - erase in line
  801. X--------------------------------------------------------------------------*/
  802. Xvoid
  803. Xansi_EL()
  804. X{
  805. Xregister uint param;
  806. Xchar cr = CR;
  807. X
  808. X    if(ansilen == 2)        /* no param */
  809. X        param = 0;
  810. X    else
  811. X        param = atoi(ansibuf + 1);
  812. X
  813. X    switch(param)
  814. X    {
  815. X        case 2:    /* clear line */
  816. X            shm->cursor_x = 0;
  817. X            if(!tty_is_ansi)
  818. X                write(TTYERR,&cr,1);
  819. X            /* fall thru */
  820. X        case 0:    /* erase to end of line */
  821. X            spaces(&shm->screen[shm->cursor_y][shm->cursor_x],
  822. X                tcap_COLS - shm->cursor_x);
  823. X            if(!tty_is_ansi)
  824. X                tcap_eeol();
  825. X            break;
  826. X        case 1:    /* erase from beginning of line */
  827. X            spaces(&shm->screen[shm->cursor_y][0],shm->cursor_x);
  828. X            if(!tty_is_ansi && shm->cursor_x)
  829. X            {
  830. X                write(TTYERR,&cr,1);
  831. X                tcap_clear_area_char(shm->cursor_x,' ');
  832. X            }
  833. X            break;
  834. X    }
  835. X
  836. X}    /* end of ansi_EL */
  837. X
  838. X/*+-------------------------------------------------------------------------
  839. X    ansi_ECH() - erase characters
  840. X--------------------------------------------------------------------------*/
  841. Xvoid
  842. Xansi_ECH()
  843. X{
  844. Xregister uint param;
  845. Xregister uint screen_pos;
  846. X
  847. X    if(ansilen == 2)        /* no param */
  848. X        param = 1;
  849. X    else
  850. X        param = atoi(ansibuf + 1);
  851. X
  852. X    if((shm->cursor_x + param) > (tcap_COLS - 1))
  853. X        return;
  854. X
  855. X    screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
  856. X    mem_cpy((char *)shm->screen + screen_pos,
  857. X           (char *)shm->screen + screen_pos + param,param);
  858. X    spaces((char *)shm->screen + ((shm->cursor_y + 1) * tcap_COLS) -
  859. X                param, param);
  860. X
  861. X    if(!tty_is_ansi)
  862. X        tcap_delete_chars(param);
  863. X
  864. X}    /* end of ansi_ECH */
  865. X
  866. X/*+-------------------------------------------------------------------------
  867. X    ansi_SU() - scroll up (new blank lines at the bottom)
  868. X--------------------------------------------------------------------------*/
  869. Xvoid
  870. Xansi_SU()
  871. X{
  872. Xregister uint param;
  873. Xregister uint count;
  874. X
  875. X    if(ansilen == 2)        /* no param */
  876. X        param = 1;
  877. X    else
  878. X        param = atoi(ansibuf + 1);
  879. X
  880. X    if(param > tcap_LINES)
  881. X        param = tcap_LINES;
  882. X    if(!param)
  883. X        return;
  884. X
  885. X#ifdef ANSI_DEBUG_3
  886. X    if(wfp)
  887. X        fprintf(wfp,"SU: param=%u y,x=%d,%d\n",param,
  888. X            shm->cursor_y,shm->cursor_x);
  889. X#endif
  890. X
  891. X    count = tcap_COLS * param;
  892. X    mem_cpy((char *)shm->screen,
  893. X        (char *)shm->screen + (tcap_COLS * param),
  894. X        LINESxCOLS - count);
  895. X    spaces(&shm->screen[shm->cursor_y][0],count);
  896. X
  897. X    if(!tty_is_ansi)
  898. X    {
  899. X        tcap_cursor(tcap_LINES - 1,0);
  900. X        while(param--)
  901. X            ff(se,"\r\n");
  902. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  903. X    }
  904. X
  905. X}    /* end of ansi_SU */
  906. X
  907. X/*+-------------------------------------------------------------------------
  908. X    ansi_SD() - scroll down (new blank lines at the top)
  909. X--------------------------------------------------------------------------*/
  910. Xvoid
  911. Xansi_SD()
  912. X{
  913. Xregister uint param;
  914. Xregister uint count;
  915. X
  916. X    if(ansilen == 2)        /* no param */
  917. X        param = 1;
  918. X    else
  919. X        param = atoi(ansibuf + 1);
  920. X
  921. X    if(param > tcap_LINES)
  922. X        param = tcap_LINES;
  923. X    if(!param)
  924. X        return;
  925. X
  926. X#ifdef ANSI_DEBUG_3
  927. X    if(wfp)
  928. X        fprintf(wfp,"SD: param=%u y,x=%d,%d\n",param,
  929. X            shm->cursor_y,shm->cursor_x);
  930. X#endif
  931. X
  932. X    count = tcap_COLS * param;
  933. X    mem_cpy((char *)shm->screen,(char *)shm->screen + count,
  934. X        LINESxCOLS - count);
  935. X    spaces((char *)shm->screen + LINESxCOLS - count,count);
  936. X
  937. X    if(!tty_is_ansi)
  938. X    {
  939. X        tcap_cursor(tcap_LINES - 1,0);
  940. X        while(param--)
  941. X            ff(se,"\r\n");
  942. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  943. X    }
  944. X
  945. X}    /* end of ansi_SD */
  946. X
  947. X/*+-------------------------------------------------------------------------
  948. X    ansi_HPA() - horizontal position absolute
  949. X--------------------------------------------------------------------------*/
  950. Xvoid
  951. Xansi_HPA()
  952. X{
  953. Xregister uint param;
  954. X
  955. X    if(ansilen == 2)        /* no param */
  956. X        param = 1;
  957. X    else
  958. X        param = atoi(ansibuf + 1);
  959. X
  960. X    if(param > (tcap_LINES - 1))
  961. X        return;
  962. X
  963. X    if((unsigned)(shm->cursor_x = param) > (unsigned)(tcap_COLS - 1))
  964. X        shm->cursor_x = tcap_COLS - 1;
  965. X
  966. X    if(!tty_is_ansi)
  967. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  968. X
  969. X}    /* end of ansi_HPA */
  970. X
  971. X/*+-------------------------------------------------------------------------
  972. X    ansi_VPA() - vertical position absolute
  973. X--------------------------------------------------------------------------*/
  974. Xvoid
  975. Xansi_VPA()
  976. X{
  977. Xregister uint param;
  978. X
  979. X    if(ansilen == 2)        /* no param */
  980. X        param = 1;
  981. X    else
  982. X        param = atoi(ansibuf + 1);
  983. X
  984. X    if(param > (tcap_COLS - 1))
  985. X        return;
  986. X
  987. X    if((unsigned)(shm->cursor_y = param) > (unsigned)(tcap_LINES - 1))
  988. X        shm->cursor_y = tcap_LINES - 1;
  989. X
  990. X    if(!tty_is_ansi)
  991. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  992. X
  993. X}    /* end of ansi_VPA */
  994. X
  995. X/*+-------------------------------------------------------------------------
  996. X    ansi_IL() - insert lines
  997. X--------------------------------------------------------------------------*/
  998. Xvoid
  999. Xansi_IL()
  1000. X{
  1001. Xregister uint param;
  1002. Xregister uint count;
  1003. Xregister uint screen_pos;
  1004. X
  1005. X    if(ansilen == 2)        /* no param */
  1006. X        param = 1;
  1007. X    else
  1008. X        param = atoi(ansibuf + 1);
  1009. X
  1010. X    if((shm->cursor_y + param) > (tcap_LINES - 1))
  1011. X        return;
  1012. X
  1013. X    count = tcap_COLS * param;
  1014. X    screen_pos = shm->cursor_y * tcap_COLS;
  1015. X    mem_cpy((char *)shm->screen + screen_pos + count,
  1016. X           (char *)shm->screen + screen_pos,
  1017. X           LINESxCOLS - screen_pos - count);
  1018. X    spaces((char *)shm->screen + screen_pos,count);
  1019. X
  1020. X    if(!tty_is_ansi)
  1021. X        tcap_insert_lines(param);
  1022. X
  1023. X}    /* end of ansi_IL */
  1024. X
  1025. X/*+-------------------------------------------------------------------------
  1026. X    ansi_ICH() - insert characters
  1027. X--------------------------------------------------------------------------*/
  1028. Xvoid
  1029. Xansi_ICH()
  1030. X{
  1031. Xregister uint param;
  1032. Xregister uint count;
  1033. Xregister uint screen_pos;
  1034. X
  1035. X    if(ansilen == 2)        /* no param */
  1036. X        param = 1;
  1037. X    else
  1038. X        param = atoi(ansibuf + 1);
  1039. X
  1040. X    if(param > tcap_COLS - shm->cursor_x)
  1041. X        param = tcap_COLS - shm->cursor_x;
  1042. X
  1043. X    if(!param)
  1044. X        return;
  1045. X
  1046. X    screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
  1047. X    count = tcap_COLS - shm->cursor_x - param;
  1048. X    mem_cpy((char *)shm->screen + screen_pos + param,
  1049. X           (char *)shm->screen + screen_pos,count);
  1050. X    spaces((char *)shm->screen + screen_pos,param);
  1051. X
  1052. X    if(!tty_is_ansi)
  1053. X        tcap_insert_chars(param);
  1054. X
  1055. X}    /* end of ansi_ICH */
  1056. X
  1057. X/*+-------------------------------------------------------------------------
  1058. X    ansi_DL() - delete lines
  1059. X--------------------------------------------------------------------------*/
  1060. Xvoid
  1061. Xansi_DL()
  1062. X{
  1063. Xregister uint param;
  1064. Xregister uint count;
  1065. Xregister uint screen_pos;
  1066. X
  1067. X    if(ansilen == 2)        /* no param */
  1068. X        param = 1;
  1069. X    else
  1070. X        param = atoi(ansibuf + 1);
  1071. X
  1072. X    if(param > (tcap_LINES - shm->cursor_y))
  1073. X        param = tcap_LINES - shm->cursor_y;
  1074. X
  1075. X    if(!param)
  1076. X        return;
  1077. X
  1078. X    count = tcap_COLS * param;
  1079. X    screen_pos = shm->cursor_y * tcap_COLS;
  1080. X    mem_cpy((char *)shm->screen + screen_pos,
  1081. X           (char *)shm->screen + screen_pos + count,
  1082. X            LINESxCOLS - screen_pos - count);
  1083. X    spaces((char *)shm->screen + LINESxCOLS - count,count);
  1084. X
  1085. X    if(!tty_is_ansi)
  1086. X        tcap_delete_lines(param);
  1087. X
  1088. X}    /* end of ansi_DL */
  1089. X
  1090. X/*+-------------------------------------------------------------------------
  1091. X    ansi_DCH() - delete characters
  1092. X--------------------------------------------------------------------------*/
  1093. Xvoid
  1094. Xansi_DCH()
  1095. X{
  1096. Xregister uint param;
  1097. Xregister uint count;
  1098. Xregister uint screen_pos;
  1099. X
  1100. X    if(ansilen == 2)        /* no param */
  1101. X        param = 1;
  1102. X    else
  1103. X        param = atoi(ansibuf + 1);
  1104. X
  1105. X    if(ansilen == 2)        /* no param */
  1106. X        param = 1;
  1107. X    else
  1108. X        param = atoi(ansibuf + 1);
  1109. X
  1110. X    if(param > tcap_COLS - shm->cursor_x)
  1111. X        param = tcap_COLS - shm->cursor_x;
  1112. X
  1113. X    if(!param)
  1114. X        return;
  1115. X
  1116. X    screen_pos = (shm->cursor_y * tcap_COLS) + shm->cursor_x;
  1117. X    count = tcap_COLS - shm->cursor_x - param;
  1118. X    mem_cpy((char *)shm->screen + screen_pos,
  1119. X            (char *)shm->screen + screen_pos + param,count);
  1120. X    screen_pos = ((shm->cursor_y + 1) * tcap_COLS) - param;
  1121. X    spaces((char *)shm->screen + screen_pos,param);
  1122. X
  1123. X    if(!tty_is_ansi)
  1124. X        tcap_delete_chars(param);
  1125. X
  1126. X}    /* end of ansi_DCH */
  1127. X
  1128. X/*+-------------------------------------------------------------------------
  1129. X    ansi_CPL() - cursor to previous line
  1130. X--------------------------------------------------------------------------*/
  1131. Xvoid
  1132. Xansi_CPL()
  1133. X{
  1134. Xregister uint param;
  1135. X
  1136. X    if(ansilen == 2)        /* no param */
  1137. X        param = 1;
  1138. X    else
  1139. X        param = atoi(ansibuf + 1);
  1140. X
  1141. X    if((shm->cursor_y -= param) > (tcap_LINES - 1))    /* unsigned comparison */
  1142. X        shm->cursor_y = 0;
  1143. X    shm->cursor_x = 0;
  1144. X
  1145. X    if(!tty_is_ansi)
  1146. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1147. X
  1148. X}    /* end of ansi_CPL */
  1149. X
  1150. X/*+-------------------------------------------------------------------------
  1151. X    ansi_CNL() - cursor to next line
  1152. X--------------------------------------------------------------------------*/
  1153. Xvoid
  1154. Xansi_CNL()
  1155. X{
  1156. Xregister uint param;
  1157. X
  1158. X    if(ansilen == 2)        /* no param */
  1159. X        param = 1;
  1160. X    else
  1161. X        param = atoi(ansibuf + 1);
  1162. X
  1163. X    if((shm->cursor_y += param) > (tcap_LINES - 1))
  1164. X        shm->cursor_y = tcap_LINES - 1;
  1165. X    shm->cursor_x = 0;
  1166. X
  1167. X    if(!tty_is_ansi)
  1168. X        tcap_cursor(shm->cursor_y,shm->cursor_x);
  1169. X
  1170. X}    /* end of ansi_CNL */
  1171. X
  1172. X/*+-------------------------------------------------------------------------
  1173. X    saved_cursor_save_cursor()
  1174. X--------------------------------------------------------------------------*/
  1175. Xvoid
  1176. Xsaved_cursor_save_cursor()
  1177. X{
  1178. X    saved_cursor_y = shm->cursor_y;
  1179. X    saved_cursor_x = shm->cursor_x;
  1180. X}    /* end of saved_cursor_save_cursor */
  1181. X
  1182. X/*+-------------------------------------------------------------------------
  1183. X    saved_cursor_restore_cursor()
  1184. X--------------------------------------------------------------------------*/
  1185. Xvoid
  1186. Xsaved_cursor_restore_cursor()
  1187. X{
  1188. X    shm->cursor_y = saved_cursor_y;
  1189. X    shm->cursor_x = saved_cursor_x;
  1190. X    tcap_cursor(shm->cursor_y,shm->cursor_x);
  1191. X}    /* end of saved_cursor_restore_cursor */
  1192. X
  1193. X/*+-------------------------------------------------------------------------
  1194. X    rcvd_ESC() - ESC seen-prepare to accumulate ansi sequence
  1195. X--------------------------------------------------------------------------*/
  1196. Xvoid
  1197. Xrcvd_ESC()
  1198. X{
  1199. X#ifdef ANSI_DEBUG
  1200. X    if(wfp)
  1201. X        fprintf(wfp,"ESC ");
  1202. X#endif
  1203. X
  1204. X    ansi = ansibuf;
  1205. X    ansilen = 0;
  1206. X    in_ansi_accumulation = 1;
  1207. X
  1208. X}    /* end of rcvd_ESC */
  1209. X
  1210. X/*+-------------------------------------------------------------------------
  1211. X    is_ansi_terminator(rchar) - is character terminator for ansi sequence?
  1212. X--------------------------------------------------------------------------*/
  1213. Xint
  1214. Xis_ansi_terminator(rchar)
  1215. Xregister uint rchar;
  1216. X{
  1217. X    return(isalpha(rchar) || (rchar == '@'));
  1218. X}    /* end of is_ansi_terminator */
  1219. X
  1220. X/*+-------------------------------------------------------------------------
  1221. X    accumulate_ansi_sequence(rchar)
  1222. X--------------------------------------------------------------------------*/
  1223. Xvoid
  1224. Xaccumulate_ansi_sequence(rchar)
  1225. Xuint rchar;
  1226. X{
  1227. X    if(ansilen == (MAX_ANSI_LEN - 2))
  1228. X    {
  1229. X        in_ansi_accumulation = 0;
  1230. X        return;
  1231. X    }
  1232. X
  1233. X#ifdef ANSI_DEBUG_2
  1234. X    if(wfp)
  1235. X        fprintf(wfp,"\naas: %02x %c ansilen=%d",
  1236. X            rchar,(rchar & 0x7F < SPACE) ? '.' : (rchar & 0x7F),ansilen);
  1237. X#endif
  1238. X
  1239. X    *ansi++ = (uchar)rchar;
  1240. X    *ansi   = 0;
  1241. X    ansilen++;
  1242. X
  1243. X}    /* end of accumulate_ansi_sequence */
  1244. X
  1245. X/*+-------------------------------------------------------------------------
  1246. X    process_ansi_sequence() - a full ansi sequence is to be decoded
  1247. X--------------------------------------------------------------------------*/
  1248. Xvoid
  1249. Xprocess_ansi_sequence()
  1250. X{
  1251. Xregister itmp;
  1252. X
  1253. X#ifdef ANSI_DEBUG
  1254. X    if(wfp)
  1255. X        fprintf(wfp,"\npas: len=%d '%s' y,x=%d,%d\n",ansilen,ansibuf,
  1256. X            shm->cursor_y,shm->cursor_x);
  1257. X#endif
  1258. X
  1259. X    if(!in_ansi_accumulation)
  1260. X        return;
  1261. X    in_ansi_accumulation = 0;
  1262. X
  1263. X    itmp = 1;        /* assume write needed */
  1264. X    if((ansilen > 1) && (ansibuf[1] == '='))
  1265. X        ;
  1266. X    else switch(ansibuf[ansilen - 1])
  1267. X    {
  1268. X        case '@': ansi_ICH(); break;
  1269. X        case 'A': ansi_CUU(); break;
  1270. X        case 'B': ansi_CUD(); break;
  1271. X        case 'C': ansi_CUF(); break;
  1272. X        case 'D': ansi_CUB(); break;
  1273. X        case 'E': ansi_CNL(); break;
  1274. X        case 'F': ansi_CPL(); break;
  1275. X        case 'H': ansi_CUP(); break;
  1276. X        case 'J': ansi_ED(); break;
  1277. X        case 'K': ansi_EL(); break;
  1278. X        case 'L': ansi_IL(); break;
  1279. X        case 'M': ansi_DL(); break;
  1280. X        case 'P': ansi_DCH(); break;
  1281. X        case 'S': ansi_SU(); break;
  1282. X        case 'T': ansi_SD(); break;
  1283. X        case 'X': ansi_ECH(); break;
  1284. X        case '`': ansi_HPA(); break;
  1285. X        case 'a': ansi_CUF(); break; /* HPR */
  1286. X        case 'd': ansi_VPA(); break;
  1287. X        case 'e': ansi_CUD(); break; /* VPR */
  1288. X        case 'f': ansi_CUP(); break; /* HVP */
  1289. X        case 'm': ansi_SGR(); itmp = 0; break;
  1290. X        case 'n': ansi_DSR(); itmp = 0; break;
  1291. X        case 's': saved_cursor_save_cursor(); itmp = 0; break;
  1292. X        case 'u': saved_cursor_restore_cursor(); itmp = 0; break;
  1293. X#ifdef FUTURES
  1294. X        case 'h': ansi_SM(); break;    /* Set Mode: SCO: lock keyboard
  1295. X                                     *           MSDOS: host of shit */
  1296. X        case 'i': ansi_MC(); break;    /* Media Copy: send screen to line */
  1297. X        case 'l': ansi_RM(); break;    /* Reset Mode: SCO: unlock keyboard
  1298. X                                     *             MSDOS: host of shit */
  1299. X#endif /* FUTURES */
  1300. X        default:
  1301. X            break;
  1302. X    }
  1303. X
  1304. X/* if proper ansi console and indicated, write the buffer to the screen */
  1305. X    if(tty_is_ansi && itmp)
  1306. X    {
  1307. X        write(TTYERR,&esc,1);
  1308. X        write(TTYERR,ansibuf,ansilen);
  1309. X    }
  1310. X
  1311. X#ifdef ANSI_DEBUG
  1312. X    if(wfp)
  1313. X        fprintf(wfp,"pas: new cursor y,x=%d,%d\n",shm->cursor_y,shm->cursor_x);
  1314. X#endif
  1315. X}    /* end of process_ansi_sequence */
  1316. X
  1317. X/*+-------------------------------------------------------------------------
  1318. X    rcvr_log_open()
  1319. X--------------------------------------------------------------------------*/
  1320. Xvoid
  1321. Xrcvr_log_open()
  1322. X{
  1323. X
  1324. X    if(rcvr_log)        /* if xmtr set us up for logging */
  1325. X    {
  1326. X        rcvr_log_fp = fopen(rcvr_log_file,rcvr_log_append ? "a" : "w");
  1327. X        rcvr_log_append = 1;    /* until next %log -s */
  1328. X        if(!rcvr_log_fp)
  1329. X        {
  1330. X            ff(se,"ecu RCVR: Could not open log file: %s\r\n",rcvr_log_file);
  1331. X            ff(se,"recording aborted.\r\n");
  1332. X        }
  1333. X        else if(!rcvr_log_raw && rcvr_log_gen_title)
  1334. X        {
  1335. X        char tstr[80];
  1336. X            get_tod(2,tstr);
  1337. X            fprintf(rcvr_log_fp,"\n====> %s (%s, %s, %s) %s\n\n",
  1338. X                shm->Lrname,shm->Llogical,
  1339. X                shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE",tstr);
  1340. X        }
  1341. X        rcvr_log_gen_title = 0;
  1342. X    }
  1343. X}    /* end of rcvr_log_open */
  1344. X
  1345. X/*+-------------------------------------------------------------------------
  1346. X    process_rcvd_char(rchar)
  1347. X--------------------------------------------------------------------------*/
  1348. Xprocess_rcvd_char(rchar)
  1349. Xregister uint rchar;
  1350. X{
  1351. Xregister itmp;
  1352. X
  1353. X    if(shm->Lparity)
  1354. X        rchar &= 0x7F;
  1355. X
  1356. X    if(want_bell_notify == 2)
  1357. X    {
  1358. X        shmr_set_xmtr_bn_1();
  1359. X        want_bell_notify = 1;
  1360. X        bell_notify(XBELL_3T);
  1361. X    }
  1362. X    else if(rchar == 7)
  1363. X    {
  1364. X        bell_notify(XBELL_ATTENTION);
  1365. X        return(0);
  1366. X    }
  1367. X
  1368. X    if(rchar == ESC)
  1369. X    {
  1370. X        rcvd_ESC();
  1371. X        return(1);
  1372. X    }
  1373. X    else if(in_ansi_accumulation)
  1374. X    {
  1375. X        accumulate_ansi_sequence(rchar);
  1376. X        if(is_ansi_terminator(rchar))
  1377. X            process_ansi_sequence();
  1378. X        return(1);
  1379. X    }
  1380. X
  1381. X#ifdef TANDEM_ENQ_ACK    /* for my friend John Dashner at Tandem */
  1382. X    if(rchar == ENQ)
  1383. X    {
  1384. X        lputc(ACK);
  1385. X        return(0);
  1386. X    }
  1387. X#endif
  1388. X
  1389. X    if(rchar < SPACE)
  1390. X    {
  1391. X        switch(rchar)
  1392. X        {
  1393. X            case CTL_L:
  1394. X                spaces((char *)shm->screen,LINESxCOLS);
  1395. X                shm->cursor_y = 0;
  1396. X                shm->cursor_x = 0;
  1397. X                break;
  1398. X
  1399. X            case BS:
  1400. X                if(shm->cursor_x)
  1401. X                    shm->cursor_x--;
  1402. X                break;
  1403. X
  1404. X            case NL:
  1405. X                if(shm->cursor_y != tcap_LINES - 1)
  1406. X                    shm->cursor_y++;
  1407. X                else
  1408. X                {
  1409. X                    mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS,
  1410. X                        LINESxCOLS - tcap_COLS);
  1411. X                    spaces(&shm->screen[shm->cursor_y][0],tcap_COLS);
  1412. X                }
  1413. X                break;
  1414. X
  1415. X            case CR:
  1416. X                shm->cursor_x = 0;
  1417. X                break;
  1418. X
  1419. X            case TAB:
  1420. X                itmp = 8 - (shm->cursor_x % 8);
  1421. X                shm->cursor_x += itmp;
  1422. X                if(shm->cursor_x >= tcap_COLS)
  1423. X                {
  1424. X                    shm->cursor_x = 0;
  1425. X                    if(++shm->cursor_y > tcap_LINES - 1)
  1426. X                        shm->cursor_y = tcap_LINES - 1;
  1427. X                }
  1428. X#ifdef old
  1429. X                else
  1430. X#endif
  1431. X                    spaces(&shm->screen[shm->cursor_y][shm->cursor_x],itmp);
  1432. X                break;
  1433. X        }
  1434. X    }
  1435. X    else
  1436. X    {
  1437. X        shm->screen[shm->cursor_y][shm->cursor_x++] = (uchar)rchar;
  1438. X        if(shm->cursor_x > tcap_COLS - 1)
  1439. X        {
  1440. X            shm->cursor_x = 0;
  1441. X            if(shm->cursor_y != tcap_LINES - 1)
  1442. X                shm->cursor_y++;
  1443. X            else
  1444. X            {
  1445. X                mem_cpy((char *)shm->screen,(char *)shm->screen + tcap_COLS,
  1446. X                    LINESxCOLS - tcap_COLS);
  1447. X                spaces(&shm->screen[shm->cursor_y][shm->cursor_x],tcap_COLS);
  1448. X            }
  1449. X        }
  1450. X    }
  1451. X
  1452. X#ifdef ANSI_DEBUG_2
  1453. X    if(wfp)
  1454. X    {
  1455. X        if((rchar & 0x7F) == NL)
  1456. X            fputs("\n",wfp);
  1457. X        else
  1458. X            fputc(((rchar & 0x7F) < SPACE) ? '.' : (rchar & 0x7F),wfp);
  1459. X    }
  1460. X#endif
  1461. X
  1462. X    if(rcvr_log && rcvr_log_fp)
  1463. X    {
  1464. X        /* if raw mode or character not excluded from "cooked" logging */
  1465. X        if(rcvr_log_raw ||
  1466. X            ((rchar >= SPACE) && (rchar <= '~')) ||
  1467. X             (rchar == NL) || (rchar == TAB))
  1468. X        {
  1469. X            putc(rchar,rcvr_log_fp);
  1470. X        }
  1471. X        /* back if log file if not raw and char is backspace */
  1472. X        else if(!rcvr_log_raw && (rchar == BS))
  1473. X        {
  1474. X        long logpos = 0;
  1475. X            if(logpos = ftell(rcvr_log_fp))
  1476. X                fseek(rcvr_log_fp,logpos - 1,0);
  1477. X        }
  1478. X
  1479. X        if(rcvr_log_flusheach)
  1480. X            fflush(rcvr_log_fp);
  1481. X    }
  1482. X    return(0);
  1483. X
  1484. X}    /* end of process_rcvd_char */
  1485. X
  1486. X/*+-----------------------------------------------------------------------
  1487. X    rcvr() - copy characters from remote line to so (fd == 1)
  1488. X------------------------------------------------------------------------*/
  1489. Xvoid
  1490. Xrcvr()
  1491. X{
  1492. Xregister itmp;
  1493. Xuchar rchar;
  1494. Xuchar nlchar = NL;
  1495. Xchar *cptr;
  1496. X
  1497. X#ifdef ANSI_DEBUG
  1498. Xchar s80[80];
  1499. X    wfp = fopen(ANSI_DEBUG_LOGFILE,"a");
  1500. X    if(ulindex(ANSI_DEBUG_LOGFILE,"/dev/tty") != -1)
  1501. X    {
  1502. X        sprintf(s80,"stty opost ocrnl < %s",ANSI_DEBUG_LOGFILE);
  1503. X        system(s80);
  1504. X    }
  1505. X    fprintf(wfp,"***************\n");
  1506. X#ifdef ANSI_DEBUG_NOBUF
  1507. X    setbuf(wfp,NULL);
  1508. X#endif /* ANSI_DEBUG_NOBUF */
  1509. X#endif /* ANSI_DEBUG */
  1510. X
  1511. X    lgetc_count = 0;
  1512. X    in_ansi_accumulation = 0;
  1513. X    ansi = ansibuf;
  1514. X    ansilen = 0;
  1515. X
  1516. X/* yetch - magic number gretching for lines and columns */
  1517. X    if(!tcap_LINES || !tcap_COLS)
  1518. X    {
  1519. X        tcap_LINES = 25;
  1520. X        tcap_COLS = 80;
  1521. X    }
  1522. X    if(tcap_LINES > 43)
  1523. X        tcap_LINES = 43;
  1524. X    if(tcap_COLS > 80)
  1525. X        tcap_COLS = 80;
  1526. X    LINESxCOLS = tcap_LINES * tcap_COLS;
  1527. X
  1528. X    rcvr_signals();
  1529. X    rcvr_log_open();
  1530. X
  1531. X    saved_cursor_y = shm->cursor_y;
  1532. X    saved_cursor_x = shm->cursor_x;
  1533. X
  1534. X    while(1)        /* receive loop - keep tight as possible! */
  1535. X    {
  1536. X        rchar = lgetc_rcvr();
  1537. X
  1538. X        if(process_rcvd_char(rchar))
  1539. X            continue;
  1540. X
  1541. X        write(TTYERR,&rchar,1);
  1542. X
  1543. X        if(shm->Ladd_nl_incoming && (rchar == CR))
  1544. X            write(TTYERR,&nlchar,1);
  1545. X
  1546. X    }
  1547. X}    /* end of rcvr */
  1548. X
  1549. X/* end of ecurcvr.c */
  1550. X/* vi: set tabstop=4 shiftwidth=4: */
  1551. SHAR_EOF
  1552. $TOUCH -am 1226051590 'ecurcvr.c' &&
  1553. chmod 0644 ecurcvr.c ||
  1554. echo 'restore of ecurcvr.c failed'
  1555. Wc_c="`wc -c < 'ecurcvr.c'`"
  1556. test 30050 -eq "$Wc_c" ||
  1557.     echo 'ecurcvr.c: original size 30050, current size' "$Wc_c"
  1558. # ============= ecuscrdump.c ==============
  1559. echo 'x - extracting ecuscrdump.c (Text)'
  1560. sed 's/^X//' << 'SHAR_EOF' > 'ecuscrdump.c' &&
  1561. X#define MULTISCREEN_DUMP_BUG
  1562. X/*+-------------------------------------------------------------------------
  1563. X    ecuscrdump.c - screen dump
  1564. X    wht@n4hgf.Mt-Park.GA.US
  1565. X
  1566. X  Defined functions:
  1567. X    screen_dump(scrfile)
  1568. X
  1569. X--------------------------------------------------------------------------*/
  1570. X/*+:EDITS:*/
  1571. X/*:12-21-1990-17:27-wht@n4hgf-non-ansi considerations */
  1572. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1573. X
  1574. X#include "ecu.h"
  1575. X#include "ecukey.h"
  1576. X#include "pc_scr.h"
  1577. X
  1578. Xextern char curr_dir[];        /* current working directory */
  1579. Xextern int rcvr_pid;
  1580. Xextern uint tcap_LINES;
  1581. Xextern uint tcap_COLS;
  1582. Xextern struct termio tty_termio_at_entry;
  1583. Xextern int tty_not_char_special;
  1584. Xextern int tty_is_multiscreen;
  1585. X
  1586. Xchar screen_dump_file_name[256];
  1587. X
  1588. X/*+-------------------------------------------------------------------------
  1589. X    screen_dump(scrfile) - dump physical display contents
  1590. Xunless stdin is non-multiscreen and/or /dev/null, in which case,
  1591. Xdump rcvr virtual screen
  1592. Xif scrfile == NULL, default to ~/.ecu/screen.dump
  1593. X--------------------------------------------------------------------------*/
  1594. Xvoid
  1595. Xscreen_dump(scrfile)
  1596. Xchar *scrfile;
  1597. X{
  1598. Xuchar s133[133];
  1599. Xuchar schar;
  1600. Xregister uchar *cptr = s133;
  1601. Xuchar *sptr;
  1602. Xint srow;
  1603. Xint scol;
  1604. XFILE *fp;
  1605. Xstruct termio dump_tty_termio_at_entry;
  1606. Xstruct termio dump_tty_termio_current;
  1607. Xint rcvr_alive = (rcvr_pid > 0);
  1608. Xint use_ansi_MC = !(!tty_is_multiscreen || tty_not_char_special);
  1609. Xuint lines_left = tcap_LINES;
  1610. Xchar *vbuf = (char *)0;
  1611. X
  1612. X    if(rcvr_alive)
  1613. X        kill_rcvr_process(SIGUSR1);
  1614. X
  1615. X    if(use_ansi_MC)
  1616. X    {
  1617. X        /* save keyboard termio at entry */
  1618. X        ioctl(TTYIN,TCGETA,(char *)&dump_tty_termio_at_entry);
  1619. X
  1620. X        /* set keyboard to termio status at staart of execution of program 
  1621. X         * plus a few mods
  1622. X         */
  1623. X
  1624. X        dump_tty_termio_current = tty_termio_at_entry;
  1625. X        dump_tty_termio_current.c_cflag &= ~(PARENB | PARODD);
  1626. X        dump_tty_termio_current.c_cflag |= CS8;
  1627. X        dump_tty_termio_current.c_iflag &= ~(ISTRIP);
  1628. X        dump_tty_termio_current.c_lflag &= ~(ICANON | ISIG | ECHO);
  1629. X        ioctl(TTYIN,TCSETAW,(char *) &dump_tty_termio_current);
  1630. X        ttyflush(2);
  1631. X    }
  1632. X
  1633. X    if(scrfile)
  1634. X        fp = fopen(scrfile,"a");
  1635. X    else
  1636. X    {
  1637. X        get_home_dir(s133);
  1638. X        strcat(s133,"/.ecu/screen.dump");
  1639. X        fp = fopen(s133,"a");
  1640. X    }
  1641. X    if(!fp)
  1642. X    {
  1643. X#if defined(MORSE)
  1644. X        xbell(XBELL_3T,1);
  1645. X#else
  1646. X        ring_bell();
  1647. X        nap(20L);
  1648. X        ring_bell();
  1649. X#endif
  1650. X        return;
  1651. X    }
  1652. X
  1653. X    if(vbuf = (char *)malloc(5120))    /* big buffer; size used elsewhere too */
  1654. X#if defined(M_XENIX)    /* bassackwards */
  1655. X        setvbuf(fp,_IOFBF,vbuf,5120);
  1656. X#else
  1657. X        setvbuf(fp,vbuf,_IOFBF,5120);
  1658. X#endif
  1659. X
  1660. X    get_tod(2,s133);
  1661. X    fprintf(fp,"====> %s (phone %s) %s\n",
  1662. X        shm->Ldescr,(shm->Ltelno[0]) ? shm->Ltelno : "NONE",s133);
  1663. X
  1664. X    if(use_ansi_MC)
  1665. X        write(1,"\033[2i",4);    /* spill your guts, screen */
  1666. X    else
  1667. X    {
  1668. X        sptr = (uchar *)shm->screen;
  1669. X        srow = 0;
  1670. X        scol = 0;
  1671. X    }
  1672. X
  1673. X    while(1)
  1674. X    {
  1675. X        if(use_ansi_MC)
  1676. X        {
  1677. X            if(!rdchk(0))
  1678. X            {
  1679. X                nap(20L);
  1680. X                if(!rdchk(0))
  1681. X                    break;
  1682. X            }
  1683. X            read(0,&schar,1);
  1684. X            if(!lines_left)
  1685. X                continue;
  1686. X        }
  1687. X        else
  1688. X        {
  1689. X            if(srow == tcap_LINES)
  1690. X                break;
  1691. X            if(scol == tcap_COLS)
  1692. X            {
  1693. X                scol = 0;
  1694. X                srow++;
  1695. X                schar = NL;
  1696. X            }
  1697. X            else
  1698. X            {
  1699. X                schar = *sptr++;
  1700. X                scol++;
  1701. X            }
  1702. X        }
  1703. X
  1704. X        if((schar > 0x7E) || (schar < 0x20))
  1705. X        {
  1706. X            switch(schar)
  1707. X            {
  1708. X            case NL:
  1709. X                while((cptr > s133) && (*(cptr - 1) == ' '))
  1710. X                    cptr--;
  1711. X                *cptr++ = 0x0A;
  1712. X                *cptr = 0;
  1713. X                fputs(s133,fp);
  1714. X                cptr = s133;
  1715. X                *cptr = 0;
  1716. X                --lines_left;
  1717. X                continue;
  1718. X
  1719. X            case at_TL:        
  1720. X                schar = vanilla_TL;
  1721. X                break;
  1722. X            case at_TR:
  1723. X                schar = vanilla_TR;
  1724. X                break;
  1725. X            case at_BL:        
  1726. X                schar = vanilla_BL;
  1727. X                break;
  1728. X            case at_BR:        
  1729. X                schar = vanilla_BR;
  1730. X                break;
  1731. X            case at_LT:            /* left hand T */
  1732. X                schar = vanilla_LT;
  1733. X                break;
  1734. X            case at_RT:            /* right hand T */
  1735. X                schar = vanilla_RT;
  1736. X                break;
  1737. X            case at_VR:            /* vertical rule */
  1738. X                schar = vanilla_VR;
  1739. X                break;
  1740. X            case at_HR:            /* horizontal rule */
  1741. X                schar = vanilla_HR;
  1742. X                break;
  1743. X            default:
  1744. X                schar = ' ';
  1745. X            }
  1746. X        }
  1747. X        *cptr++ = schar;
  1748. X    }
  1749. X
  1750. X    if(use_ansi_MC)
  1751. X    {
  1752. X        /* restore keyboard termio at entry */
  1753. X        ioctl(TTYIN,TCSETAW,(char *)&dump_tty_termio_at_entry);
  1754. X        ttyflush(2);
  1755. X#if defined(MULTISCREEN_DUMP_BUG)
  1756. X        /*
  1757. X         * bug in 2.3.1 sco video driver leaves "ESC[2" active;
  1758. X         * use "l" (unlock tty) a noop
  1759. X         */
  1760. X        fputs("l",stdout);
  1761. X#endif /* MULTISCREEN_DUMP_BUG */
  1762. X    }
  1763. X
  1764. X    fclose(fp);
  1765. X
  1766. X    if(vbuf)
  1767. X        free(vbuf);
  1768. X
  1769. X#if defined(MORSE)
  1770. X    xbell(XBELL_DONE,1);
  1771. X#else
  1772. X    ring_bell();
  1773. X#endif
  1774. X
  1775. X    if(rcvr_alive)
  1776. X        start_rcvr_process(0);
  1777. X
  1778. X}    /* end of screen_dump */
  1779. SHAR_EOF
  1780. $TOUCH -am 1224223390 'ecuscrdump.c' &&
  1781. chmod 0644 ecuscrdump.c ||
  1782. echo 'restore of ecuscrdump.c failed'
  1783. Wc_c="`wc -c < 'ecuscrdump.c'`"
  1784. test 4434 -eq "$Wc_c" ||
  1785.     echo 'ecuscrdump.c: original size 4434, current size' "$Wc_c"
  1786. true || echo 'restore of ecusetup.c failed'
  1787. echo End of part 6, continue with part 7
  1788. exit 0
  1789. --------------------------------------------------------------------
  1790. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  1791. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  1792.  
  1793. exit 0 # Just in case...
  1794. -- 
  1795. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1796. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1797. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1798. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1799.